package com.xiaolin.structure.tree.common;

import com.xiaolin.structure.tree.node.Node;
import lombok.Data;
import lombok.ToString;

/**
 * @ClassName BinaryTree
 * @Description 普通二叉树-链表实现
 * @Detail detail
 * @Author MyPC
 * @Date 2020/11/17
 * @Version 1.0
 */
public class BinaryTree<E> {

    // 根节点
    private Node<E> root;

    public void setRoot(Node<E> root){
        this.root=root;
    }

    public Node<E> getRoot() {
        return root;
    }

    public Node<E> buildTree(E[] arr){
        if(arr.length>0){

        }
        return root;
    }

    /**
     * 前序遍历
     */
    public void preTraverse(){
        if(this.root==null){
            System.out.println("树为空");
        }else {
            this.root.preTraverse();
        }
    }

    /**
     * 中序遍历
     */
    public void midTraverse(){
        if(this.root==null){
            System.out.println("树为空");
        }else {
            this.root.midTraverse();
        }
    }

    /**
     * 后序遍历
     */
    public void afterTraverse(){
        if(this.root==null){
            System.out.println("树为空");
        }else {
            this.root.afterTraverse();
        }
    }

    /**
     * @ClassName Student
     * @Description TODO
     * @Detail detail
     * @Author MyPC
     * @Date 2020/11/17
     * @Version 1.0
     */
    @Data
    @ToString
    public static class Student {
        private int age;
        private String name;
        public Student(int age,String name){
            this.age=age;
            this.name=name;
        }
    }
}
